<template>
	<view class="choose-btn" @tap="chooseImg"> </view>
</template>

<script setup>
	import { uploadImgApi } from '@/service/index.js'
	const emit = defineEmits(['choose'])
	const props = defineProps({
		fileType: {
			type: String,
			default: 'img'
		},
		disabled: {
			type: Boolean,
			default: false
		}
	})
	const chooseImg = () => {
		if(props.disabled) return
		if (props.fileType == 'img') {
			uni.chooseImage({
				count: 1,
				success: (res) => {
					uploadImgApi(res.tempFilePaths[0]).then(res => {
						emit('choose', {id: res.id, img_url: res.path} )
					})
				}
			})
		} else {
			uni.chooseVideo({
				sourceType: 'album',
				success: (res) => {
					uploadImgApi(res.tempFilePath).then(res => {
						emit('choose', {id: res.id, img_url: res.path} )
					})
				}
			})
		}
	}
</script>

<style scoped lang="scss">
	.choose-btn {
		width: 74px;
		height: 74px;
		position: relative;
		background: #F4F4F4;
		border-radius: 10px;
		&::after {
		  position: absolute;
		  top: 50%;
		  left: 50%;
		  transform: translate(-50%, -50%);
		  display: block;
		  content: '';
		  width: 24px;
		  height: 2px;
		  background: #D8D8D8;
		}
		&::before {
		  position: absolute;
		  top: 50%;
		  left: 50%;
		  transform: translate(-50%, -50%);
		  display: block;
		  content: '';
		  width: 2px;
		  height: 24px;
		  background: #D8D8D8;
		}
	}
</style>